package br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.jpa;

import javax.persistence.EntityManager;

import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ChannelDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ClientDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.DAOFactory;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ProfileDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ProgramDAO;

public class JPADAOFactory extends DAOFactory {

	private static JPADAOFactory instance = null;
	private EntityManager emf;
	private ProgramDAO programDAO;
	private ChannelDAO channelDAO;
	private ClientDAO clientDAO;
	private ProfileDAO profileDAO;

	private JPADAOFactory() {
		emf = EMF.get().createEntityManager();
		programDAO = new JPAProgramDAO(emf);
		channelDAO = new JPAChannelDAO(emf);
		clientDAO = new JPAClientDAO(emf);
		profileDAO = new JPAProfileDAO(emf);
	}

	public static JPADAOFactory getInstance() {
		if (instance == null) {
			instance = new JPADAOFactory();
		}
		return instance;
	}

	@Override
	public ProgramDAO getProgramDAO() {
		return programDAO;
	}

	@Override
	public ChannelDAO getChannelDAO() {
		return channelDAO;
	}

	@Override
	public ClientDAO getClientDAO() {
		return clientDAO;
	}

	@Override
	public ProfileDAO getProfileDAO() {
		return profileDAO;
	}

}
